<?php
require_once("../../config.php");
require_once("WDIALOG.class.php");
set_time_limit(0);
//当前操作目录
if(isset($_REQUEST['curr_dir']))
	$curr_dir=$_REQUEST['curr_dir'];
else 
	$curr_dir = "";

//根目录
if(isset($_REQUEST['pDir']))
	$pDir=$_REQUEST['pDir'];
else 
	$pDir= "/upload";
//窗口类型
$type= "0";
//文件类型过滤
if(isset($_REQUEST['filetypes']))
	$filetypes=$_REQUEST['filetypes'];
else 
	$filetypes="jpg";

if(isset($_REQUEST['basedir']))
	$basedir=$_REQUEST['basedir'];
else 
	$basedir="";
if(empty($curr_dir))
	$curr_dir=$pDir;
else 
	$curr_dir = $pDir . $curr_dir;
//排列类型	
$sorttype = 1;
if(isset($_POST['sorttype']) && $_POST['sorttype'] == "2")
	$sorttype = 2;
$dialog=new WDIALOG($pDir,$type);
$dialog->setBaseDir(".");
$dialog->setCurrentDir($curr_dir);
$dialog->setFileType($filetypes);

$title="浏览";
?>
<html>
<head>
<title><?php echo $title?></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
body,td
{
	font-family:verdana;
	font-size:11px;
}
a{
text-decoration:none;
color:#000000;
}
a:hover
{
text-decoration:underline;
}
.title{
background-color:#BBBBBB;
color:#FFFFFF;
font-weight:bold;
height:25px;
padding-left:5px;
}
.filebox
{
	border:1px solid #CCCCCC;
	width:<?=$dialog->boxWidth-20?>;
	height:<?=$dialog->boxHeight-100?>;
	overflow:auto;
}


</style>
<script language="javascript">
function chDir(dir)
{
	if(dir==null || dir=="" )
		dir="";
	for(i=0;i<document.form1.curr_dir.options.length;i++)
	{
		if(document.form1.curr_dir.options[i].value==dir)
		{
			document.form1.curr_dir.options[i].selected=true;
			document.form1.submit();
		}
	}
}

function selFile(file)
{
	document.form1.filename.value=file;
}

function openFile(type)
{
	if(type == 2)
		window.open("<?php echo $dialog->currentDir?>/"+document.form1.filename.value,"_blank");
	else
	{
		
		window.opener.document.<?=$_GET['form']?>.<?=$_GET['formname']?>.value= "<?php echo $dialog->currentDir?>/"+document.form1.filename.value;
		window.opener.document.getElementById("upload_view_<?=$_GET['formname']?>").innerHTML = "<a href=\"<?php echo $dialog->currentDir?>/"+document.form1.filename.value + "\" target=\"_blank\">浏览</a>"
		window.close();
	}
}
</script>
</head>
<body leftmargin="0" topmargin="0">
<table width='100%' border=0 cellpadding="0" cellspacing="0" height="100%">
<form name='form1' action="" method="POST">
<input type="hidden" name="title" value="<?php echo $title?>">
<input type="hidden" name="pDir" value="<?php echo $pDir?>">
<input type="hidden" name="type" value="<?php echo $type?>">
<input type="hidden" name="filetypes" value="<?php echo $filetypes?>">
<input type="hidden" name="basedir" value="<?php echo $basedir?>">
<input type="hidden" name="act" value="xxx">
<input type="hidden" name="variable" value="xxx">
<tr class="title"><td align='left' valign="top" height="30">
	<table style='margin-left:10px' >
	<tr><td><?php echo $title?></td>
	<td><select name='curr_dir' onchange="javascript:document.form1.submit();">
		<?php
			echo "<option value=''>/</option>";
			
			$pdir_arr=$dialog->getParentDirForCurrentDir();
			$parentdir="";
			for($i=0;$i<count($pdir_arr);$i++)
			{
				$parentdir.="/".$pdir_arr[$i];
				echo "<option value='$parentdir' selected>".$parentdir."</option>";
			}
			$dialog->readDir();
			$dir_arr=$dialog->dirincurrdir;
			for($i=0;$i<count($dir_arr);$i++)
			{
				if(isset($dir_arr[$i]))
				{
					$virtual = str_replace(DOCUMENTROOT.$dialog->parentDir,"",$dir_arr[$i]);
					echo "<option value='$virtual'>$virtual</option>";
				}
			}
		?>
		</select>
	</td> 
	<td><a href='javascript:chDir()'><img src='<?php echo $dialog->iconDir."btnFolderUp.gif"?>' border=0></a></td>
	</tr>
	</table>
</td></tr>
<tr><td style="height:30px;">&nbsp;&nbsp;<input type="radio" name="sorttype" value="1" checked onclick="document.form1.submit();">平铺 <input type="radio" name="sorttype" value="2" onclick="document.form1.submit();" <?if($sorttype == 2) print("checked");?>>缩略图</td></tr>
<tr><td align='left'>
	<div style='margin-left:10px' class="filebox">
	<table  cellpadding="0" cellspacing="0" border="0" >
	<tr><td><?php
		echo $dialog->getFilesInCurrentDir($sorttype);
	?></td></tr>
	</table></div>
	</td>
</tr>
<tr><td height="30" valign="top" >
	<table cellpadding="5" cellspacing="0" border="0" style='margin-left:10px'>
	<tr><td>文件名：</td><td><input name='filename' size=20 readonly></td>
	<td><input type="button" name="saveFile" value="选中" class="btn" onclick="openFile(1)"></td>
	<td><input type="button" name="saveFile" value="预览" class="btn" onclick="openFile(2)"></td>
	<td><input type="button" onclick="javascript:window.close();" value="放弃" class="btn"></td>
	</tr>
	</table>
</td> </tr>
</form>
</table>
</body>
</html>